import { defineStore } from 'pinia';
import router from '@/router/index';
import { usePageStore} from './page';
import { SecureSS } from '../../utils/common';
const ss = new SecureSS();
export const useUserStore = defineStore('user', {
    state: () => ({
      userInfo: null,
      auth:[],
      token:null,
      appSecret:null,
    }),
    getters: {

    },
    actions: {
      setUser(user) {
        let info = {username:user.username,nickName:user.nickName,avatar:user.avatar,role:user.role,creationTime:user.creationTime};
        this.userInfo = info;
        this.auth=user.auth;
        this.token=user.sys_token;
        this.appSecret=user.appSecret;
      },
      loginOut(){
        router.push({ name: 'Login' });
        this.$reset();
        sessionStorage.clear();
        usePageStore().resetPage();
      }
    },
    persist: {
      key:'aai',
      paths: ['auth','userInfo','token','appSecret'],
      storage: ss,
    }
})